
6-3  ĬĿ¼TestFile.txtļд뼸ıϢ
Imports System.IO
Module StreamWrite
     Public Sub Main()
        Dim sw As StreamWriter = New StreamWriter("TestFile.txt")
        sw.Write("This is the ")
        sw.WriteLine("header for the file.")
        sw.WriteLine("-------------------")
        sw.Write("The date is: ")
        sw.WriteLine(DateTime.Now)
        sw.Close()
    End Sub
End Module

 

ҪTestFile.txtļȫͨгʵ֡
Sub ReadTextFromFile()
    Dim file As New System.IO.StreamReader("TestFile.txt")
    Dim words As String = file.ReadToEnd()
    Console.WriteLine(words)
    file.Close()
End Sub

ԴļжȡһУȻÿı̨
Dim file As New System.IO.StreamReader("c:\test.txt")
        Dim oneLine As String
        oneLine = file.ReadLine()
        While (oneLine <> "")
            Console.WriteLine(oneLine)
            oneLine = file.ReadLine()
        End While
        file.Close()
